package com.eric.husky.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import com.eric.husky.common.CommonController;
import com.eric.husky.common.web.ResponseModel;
import com.eric.husky.bean.Vip;
import com.eric.husky.service.VipService;
import java.util.List;

@RequestMapping(value = "/vip")
@RestController
@Api(value="会员管理接口",tags={"Vip(会员管理)-增删改查;导入导出"})
public class VipController extends CommonController{

	@Autowired
	private VipService vipService;

	@ApiOperation(value = "获取分页数据" ,notes = "获取分页数据" )
    @GetMapping("/list")
    public Page<Vip> list(Vip vip, Pageable page) {
        return vipService.list(vip, page);
    }

    @ApiOperation(value = "获取列表数据" ,notes = "获取列表数据" )
	@GetMapping("/findAll")
	public List<Vip> findAll(){
		return vipService.findList();
	}

    @ApiOperation(value = "获取单条数据对象" ,notes = "获取单条数据对象")
	@ApiImplicitParams({
		@ApiImplicitParam(paramType = "query",name = "vipid" ,value = "vipID" , required = true, dataType = "Integer")
	})
	@GetMapping("/{vipid}")
    public Vip get(@PathVariable Integer vipid) {
		return vipService.get(vipid);
    }

    @ApiOperation(value = "保存单条数据", notes = "保存单条数据,id列为空则为新增,不为空则为修改")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "Vip",value = "vip",required = false,dataType = "Vip")
    })
    @PostMapping("/save")
    public Vip save(@RequestBody Vip vip) {
		return vipService.save(vip);
    }

    @ApiOperation(value = "删除会员管理", notes = "删除会员管理" )
    @ApiImplicitParams({ @ApiImplicitParam(name = "vipids", value = "VipID", required = true, dataType = "String")
    })
    @RequestMapping(value = "/delete" ,method = { RequestMethod.DELETE})
    public ResponseModel delete(String vipids) {
        try {
            String[] id_array = vipids.split(",");
            for(String vipid:id_array){
                vipService.delete(Integer.parseInt(vipid));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseModel.success("删除成功");
    }

}